<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" href="../../css/aui.css" type="text/css">
    <style media="screen">
        .label-position {
            position: absolute;
            top: 50%;
            right: 30px;
        }
    </style>
</head>

<body>
    <ul class="aui-list aui-media-list">
        <li class="aui-list-item aui-list-item-middle" tapmode="tap-active" onclick="handlePage()">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-media" style="width: 3rem;">
                    <img src="../../image/demo01.jpeg" class="aui-img-round aui-list-img-sm">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title">材料管理</div>
                        <div class="aui-list-item-right">
                            <span class="aui-text-danger cdb aui-font-size-20"></span>待办项
                        </div>
                    </div>
                </div>
            </div>
        </li>
        <li class="aui-list-item aui-list-item-middle" tapmode="tap-active" onclick="handlezl()">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-media" style="width: 3rem;">
                    <img src="../../image/demo02.jpeg" class="aui-img-round aui-list-img-sm">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title">质量整改</div>
                        <div class="aui-list-item-right">
                            <span class="aui-text-danger zdb aui-font-size-20">100</span>待办项
                        </div>
                    </div>
                </div>
            </div>
        </li>
        <li class="aui-list-item aui-list-item-middle" tapmode="tap-active" onclick="handlesafe()">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-media" style="width: 3rem;">
                    <img src="../../image/demo01.jpeg" class="aui-img-round aui-list-img-sm">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title">安全整改</div>
                        <div class="aui-list-item-right">
                            <span class="aui-text-danger adb aui-font-size-20">100</span>待办项
                        </div>
                    </div>
                </div>
            </div>
        </li>
    </ul>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    apiready = function() {
        // console.log(JSON.stringify(api.windows()));
        api.addEventListener({
            name: 'pageIndexChange'
        }, function(ret, err){
            // console.log(`33`);
            // console.log(JSON.stringify(ret));
            Init();
        });

        Init();
        initRefresh();
    }

    // 初始化数据
    function Init() {
        let token = $api.getStorage('token');
        let uid = $api.getStorage('uid');
        api.ajax({
            url: $api.SERVE_URL + 'index.php/index/index/index',
            method: 'post',
            headers: {
                "token": token
            },
            data: {
                values: {
                    'token_uid': uid
                }
            }
        }, function(ret, err) {
          // console.log(`ret`);
          // console.log(JSON.stringify(ret));
          // console.log(`err`);
          // console.log(JSON.stringify(err));
            if (ret) {
                if (ret.code === 200) {
                    api.refreshHeaderLoadDone();
                    let params = ret.data;
                    $api.text(document.querySelector(".cdb"), params.material.b);
                    $api.text(document.querySelector(".zdb"), params.quality.b);
                    $api.text(document.querySelector(".adb"), params.safe.b);
                } else if (ret.code === 401) {
                    $api.clearStorage();
                    tologin();
                } else {
                    api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                    tologin();
                }
            } else {
                api.toast({
                    msg: '数据发生错误！',
                    duration: 2000,
                    location: 'top'
                });
                tologin();
            }
        });
    }
    function tologin () {
      setTimeout(function() {
          api.closeToWin({
              name: 'root'
          });
      }, 1500)
    }
    // 材料管理
    function handlePage() {
        api.openWin({
            name: 'home',
            url: './list.html',
            pageParam: {
                name: 'home'
            }
        });
    }
    // 质量整改
    function handlezl() {
        api.openWin({
            name: 'material',
            url: './material.html',
            pageParam: {
                name: 'material'
            }
        });
    }
    // 安全整改
    function handlesafe() {
        api.openWin({
            name: 'safe',
            url: './safe.html',
            pageParam: {
                name: 'safe'
            }
        });
    }
    // 下拉刷新
    function initRefresh() {
        api.setRefreshHeaderInfo({
            visible: true,
            loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            // console.log(`refreshHeaderLoading`);
            Init();
        });
    }
</script>

</html>
